<extend name="Index:base" />
<block name="title"><title>商品分类</title></block>
<block name="style">
 <style>
.main,.panel-default>.panel-heading{
background:none;
}
body{
background:none;
}
.panel.panel-default,.panel .panel-body,.panel .panel-heading,.table-bordered {
	border:none;
}
.table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
	border:none;		
	padding:15px;	
	line-height:8px;
	height: 8px;
	border-top: 1px solid #d4d4d4;
	border-bottom: 1px solid #d4d4d4;
}
.name strong{
color:#000000;
font-size:15px;
font-weight:600;
}
.name {
	color:#20a8d8;
	font-size:12px;
}
.smallfont {
	color:#9c9c9c;
	font-size:12px;
}

.align-center{
	text-align:center; 
}
.title2{
text-align:center;
}
.table-bordered > tbody > tr .wd{
	text-align:left;	
}

.col-xs-2,.col-xs-4{
padding-right:0;
margin:10px 0;
}
.col-sm-3{
width:10%;
}
.col-sm-2{
width:8%;
}
.col-sm-1{
width:5%;
}
.col-sm-4{
width:18%;
}
.col-sm-1,.col-sm-2{
margin:16px 0;
}
.col-sm-3,.col-sm-4{
margin:10px 0;
}
.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4{
padding-right:0;
}
 </style>
</block>
	<!-- start: Header -->
<block name="body">

			<!-- end: Main Menu -->
						
		<!-- start: Content -->
		<div class="main ">
		
			<div class="row">
				<div class="col-lg-12">
					<h3 class="page-header"><i class="fa fa-life-bouy"></i>分类管理</h3>
				</div>
			</div>

			<div class="row">		
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<h2><span class="break"></span><strong>管理</strong></h2>&nbsp;&nbsp;&nbsp;
							<a class="btn btn-default " href="#" id="gc_add">新增</i></a>
												
						</div>&nbsp;&nbsp;&nbsp;
						<ol class="breadcrumb" style="height:100px;background-color: #ffffff;">							
							<li><i class="fa fa-warning"></i><a href="#">操作提示：</a></li><br/>	
							<li><font style="font-size:15px;color:red;">商品分类下有相关商品或者店铺时，请勿删除和修改，以免影响商品的正常展示和商家正常发布商品</font></br>
							<font style="font-size:8px;color:#888;">当店主添加商品时可选择商品分类，用户可根据分类查询商品列表,点击分类名前“+”符号，显示当前分类的下级分类</font>
							</li>							
						</ol>
						<div class="panel-body">

							<table class="table table-striped table-bordered bootstrap-datatable datatable">
							  <thead>
								  <tr>
									  
                                      <th>排序</th>
									  <th class="">分类名称</th>
									  <th class="title2">是否在首页展示</th>
									  <th class="title2">分佣比例</th>
									  <th class="title2">操作</th>
								  </tr>
							  </thead>   
							  <tbody id="state">
								<volist name="g_class" id="vo">
								<tr>
									
									<td>{$vo.gc_sort}</td>
									<td class="wd">
										<a href="javascript:;" data-type="parent"  data-id="{$vo.gc_id}"><i class="fa fa-plus-square" ></i></a> &nbsp;{$vo.gc_name}
									</td>
									<td class="align-center">
										<if condition="$vo.gc_show eq '1'">
											是
										<else/>		
											否
										</if>
									</td>									
									 <td class="align-center">{$vo.commis_rate}&nbsp;%</td>

									<td class="align-center">
										<a class="label label-primary"  href="{:U('Goods/index')}?id={$vo.gc_id}" >编辑</i>
										</a>
										<if condition="$vo.sg_sort eq '0'">
										<a href="#" >												
										&nbsp;&nbsp;<span class="label label-danger" style="background-color: #999;">默认等级不能删除</span>
										</a>
										
										<else/>
										<a href="#" data-type="del" data-id="{$vo.gc_id}">
												
										&nbsp;&nbsp;<span class="label label-danger" >删除</span>
										</a>
										</if>											
									 </td>

								</tr>
								
								</volist>
							  </tbody>
						  </table>  
							<ul class="pagination">
								{$page}
							 </ul>						  
						</div>
					</div>
				</div><!--/col
			
			</div><!--/row-->				
			
		<!-- end: Content -->
		<br><br><br>
		
	</div><!--/container-->
	
</block>
<block name="script">

<script>



	$("#gc_add").live('click',function(){

			$.ajax({
				url:"{:U('Goods/index')}",
				data:{gc_add:'gc_add'},
				type:'get',
				//dataType:'json',
				success:function (e) {
					window.location.href ="{:U('Goods/index')}?gc_add=gc_add";
				}
			});	
	});
	$(".align-center a").click(function(){

		var id = $(this).attr('data-id');
		var type = $(this).attr('data-type');
		//alert(type);
		if (type=='del') {
			if(confirm("确定要删除吗？")){		
				//是	
				$.ajax({
					url:"{:U('Store/del')}",
					data:{id:id,table:4,str:'gc_id'},
					type:'post',
					dataType:'json',
					success:function (e) {			
					
						alert(e.info); 
						location.reload();				
					}
				});			
			}else{
				//否
				return false;
			}	
		}

	});
	//二级分类
	$('.fa-plus-square').live('click',function(){

		   var id = $(this).parent().attr('data-id');
		   var $this = $(this);
		   var parent =  $this.parent().parent().parent().html();
		   

		 if(id){
				$.ajax({
					url:"{:U('Goods/gc_chlidren')}",
					data:{id:id,type:'findson'},
					type:'post',
					dataType:'json',
					success:function (e) {
						var html='';
						var a = e.info;
						if (e.info) {
							 
							for(var i=0;i<a.length;i++){
								var gc_show = a[i].gc_show ;
								if (gc_show=='1') {
									gc_show = '是' ;
								} else {
									gc_show = '否' ;
								}
								var url = "{:U('Goods/index')}?id="+a[i].gc_id ;
								
								html += '<tr data-type="son'+a[i].gc_parent_id+'"><td>'+a[i].gc_sort+'</td><td class="wd"><a href="javascript:;" data-id="'+a[i].gc_id+'"><i class="fa fa-plus-square" ></i></a>&nbsp;<img fieldid="258" status="open" nc_type="flex" src="__PUBLIC__/Home/images/tv-item1.png">'+a[i].gc_name+'</td><td class="align-center">'+gc_show+'</td><td class="align-center">'+a[i].commis_rate+'&nbsp;%</td><td class="align-center"><a class="label label-primary"  href="'+url+'" >编辑</i></a>';
								
								var sg_sort = a[i].sg_sort ;
								if (sg_sort=='0') {
								  html += '<a href="#" >&nbsp;&nbsp;<span class="label label-danger" style="background-color: #999;">默认等级不能删除</span></a>' ;
								} else{
									html += '<a href="#" data-type="del" data-id="'+a[i].gc_id+'">&nbsp;&nbsp;<span class="label label-danger" >删除</span></a>' ;
								}
								html +=  '</td></tr>' ;	
								var j = i+1 ; 
								if(j==a.length){
									//alert(i);
									$this.removeClass('fa-plus-square') ;
									$this.addClass('fa-minus-square') ;
									$this.parent().parent().parent().after(html);
								}																
							}	
						}
						$this.removeClass('fa-plus-square') ;
						$this.addClass('fa-minus-square') ;
										
					}
			});		 
		 } 

	});

	$('.fa-minus-square').live('click', function(){
		    var $this = $(this);
			var id = $(this).parent().attr('data-id');
			var son = $this.parent().parent().parent().nextAll('[data-type="son'+id+'"]').remove();
			//alert(son);	
			var css = $this.attr('class') ;
			if (css=='fa fa-minus-square') {		    
				$this.removeClass('fa-minus-square') ;
				$this.addClass('fa-plus-square') ;
				$this.parent().parent().parent().nextAll('[data-type="son'+id+'"]').remove();
			}
	});

</script>
</block>	









